import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class E3T1 {
    public static void dfs(int num,int[][] matrix,int[] visited,StringBuilder stringBuilder) {
        visited[num] = 1;
        stringBuilder.append(num+" ");
        for (int i = 0; i < visited.length; i++) {
            if(visited[i]==0&&matrix[i][num]>0) {
                dfs(i,matrix,visited,stringBuilder);
            }
        }
    }
    public static void bfs(int num,int[][] matrix,int[] visited,StringBuilder stringBuilder) {
        visited[num] = 1;
        stringBuilder.append(num+" ");
        Queue<Integer> q = new LinkedList<>();
        q.offer(num);
        while(!q.isEmpty()) {
            int n =  q.poll();
            for (int i = 0; i < visited.length; i++) {
                if(visited[i]==0&&matrix[i][n]>0) {
                    visited[i] = 1;
                    stringBuilder.append(i+" ");
                    q.offer(i);
                }
            }
        }
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int E = scanner.nextInt();
        int[][] matrix = new int[N][N];
        int[] dfsVisited = new int[N];
        int[] bfsVisited = new int[N];
        for (int i = 0; i < E; i++) {
            int num1 = scanner.nextInt();
            int num2 = scanner.nextInt();
            matrix[num1][num2] = 1;
            matrix[num2][num1] = 1;
        }
        for (int i = 0; i < N; i++) {
            if(dfsVisited[i]==0) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("{");
                dfs(i,matrix,dfsVisited,stringBuilder);
                stringBuilder = new StringBuilder(stringBuilder.toString().substring(0,stringBuilder.toString().length()-1));
                stringBuilder.append("}");
                System.out.println(stringBuilder);
            }
        }
        for (int i = 0; i < N; i++) {
            if(bfsVisited[i]==0) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("{");
                bfs(i,matrix,bfsVisited,stringBuilder);
                stringBuilder = new StringBuilder(stringBuilder.toString().substring(0,stringBuilder.toString().length()-1));
                stringBuilder.append("}");
                System.out.println(stringBuilder);
            }
        }
    }
}
